const expressSession = require('express-session')
const redis = require('redis')
const RedisStore = require('connect-redis')(expressSession)
const path = require("path")
const savePageFile = path.join(__dirname, '../public/page/',);
const saveCSVFile = path.join(__dirname, '../public/page/',);
const redisConfig = {
  host: '127.0.0.1',
  port: '6379',
  ttl: 1000 * 60 * 5,
  password: '',
}
let redisClient = null
if (!redisConfig.password) {
  redisClient = redis.createClient(redisConfig.port, redisConfig.host)
} else {
  redisClient = redis.createClient(redisConfig.port, redisConfig.host, {
    auth_pass: redisConfig.password,
  })
  redisClient.auth(redisConfig.password, function () {
    console.log('连接成功')
    redisClient.on('ready', (res) => {
      console.log('redis启动成功')
    })
    redisClient.on('connect', () => {
      console.log('redis connect success')
    })

    redisClient.on('error', (err) => {
      console.log('redis启动失败', err)
    })
  })
}

const session = {
  store: new RedisStore({ client: redisClient }),
  secret: 'password',
  resave: false,
  saveUninitialized: false,
  cookie: {
    maxAge: 1000 * 60 * 5, // default session expiration is set to 1 hour
  },
}

const basePage = {
  "pageConfig": {
    width: 1920,
    height: 1080,
    bgColor: "rgba(13, 42, 67, 0)",
    bgImage: "https://files.pengxiaotian.com/datav/bj.png",
    grid: 8,
    screenshot: "",
    zoomMode: 0,
    useWatermark: false,
    pageFilters: [],
    styleFilterParams: {
      enable: false,
      hue: 0,
      saturate: 100,
      brightness: 100,
      contrast: 100,
      opacity: 100,
    },
    flow: {},
    variables: {
      componentsView: {},
      publishersView: {},
      subscribersView: {},
    },
  },
  "components": []
}

module.exports = {
  port: 8086,
  session,
  sqldb: {
    db: 'mysql',
    host: 'localhost',
    port: 3306,
    database: 'vite_server',
    username: 'root',
    password: 'fwq123',
    timezone: '+08:00', //for writing to database
  },
  redisConfig,
  SUPER_ID: 1,
  admin_password: 'admin',
  saltTime: 6,
  port: 8086, // 生产环境运行端口号
  secretOrKey: 'admin-token', // jwtFromRequest token
  defaultpassword: '123456',
  redisClient,
  basePage,
  savePageFile,
  saveCSVFile
}
